package cn.edu.zafu.bigdata.x.zzzznnn.d;

class InvalidAgeException extends Exception {
    public InvalidAgeException(String message) {
        super(message);
    }
}

public class CustomExceptionExample {
    public static void checkAge(int age) throws InvalidAgeException {
        if (age < 18) {
            throw new InvalidAgeException("年龄小于 18 岁，不合法。");
        }
        System.out.println("年龄合法。");
    }

    public static void main(String[] args) {
        try {
            checkAge(16);
        } catch (InvalidAgeException e) {
            System.out.println("发生错误：" + e.getMessage());
        }
    }
}